package com.ruoyi.veterinary.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.veterinary.mapper.VetInventoryMapper;
import com.ruoyi.veterinary.domain.VetInventory;
import com.ruoyi.veterinary.service.IVetInventoryService;

/**
 * 仓库管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-19
 */
@Service
public class VetInventoryServiceImpl implements IVetInventoryService 
{
    @Autowired
    private VetInventoryMapper vetInventoryMapper;

    /**
     * 查询仓库管理
     * 
     * @param inventoryId 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public VetInventory selectVetInventoryByInventoryId(Long inventoryId)
    {
        return vetInventoryMapper.selectVetInventoryByInventoryId(inventoryId);
    }

    /**
     * 查询仓库管理列表
     * 
     * @param vetInventory 仓库管理
     * @return 仓库管理
     */
    @Override
    public List<VetInventory> selectVetInventoryList(VetInventory vetInventory)
    {
        return vetInventoryMapper.selectVetInventoryList(vetInventory);
    }

    /**
     * 新增仓库管理
     * 
     * @param vetInventory 仓库管理
     * @return 结果
     */
    @Override
    public int insertVetInventory(VetInventory vetInventory)
    {
        vetInventory.setCreateTime(DateUtils.getNowDate());
        return vetInventoryMapper.insertVetInventory(vetInventory);
    }

    /**
     * 修改仓库管理
     * 
     * @param vetInventory 仓库管理
     * @return 结果
     */
    @Override
    public int updateVetInventory(VetInventory vetInventory)
    {
        vetInventory.setUpdateTime(DateUtils.getNowDate());
        return vetInventoryMapper.updateVetInventory(vetInventory);
    }

    /**
     * 批量删除仓库管理
     * 
     * @param inventoryIds 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteVetInventoryByInventoryIds(Long[] inventoryIds)
    {
        return vetInventoryMapper.deleteVetInventoryByInventoryIds(inventoryIds);
    }

    /**
     * 删除仓库管理信息
     * 
     * @param inventoryId 仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteVetInventoryByInventoryId(Long inventoryId)
    {
        return vetInventoryMapper.deleteVetInventoryByInventoryId(inventoryId);
    }

    /**
     * 查询库存预警列表
     * 
     * @return 库存预警集合
     */
    @Override
    public List<VetInventory> selectInventoryWarningList()
    {
        return vetInventoryMapper.selectInventoryWarningList();
    }

    /**
     * 查询即将过期药品列表
     * 
     * @param days 天数
     * @return 即将过期药品集合
     */
    @Override
    public List<VetInventory> selectExpiringDrugList(Integer days)
    {
        return vetInventoryMapper.selectExpiringDrugList(days);
    }

    /**
     * 根据药品名称和批号查询库存
     * 
     * @param drugName 药品名称
     * @param batchNumber 批号
     * @return 库存信息
     */
    @Override
    public VetInventory selectInventoryByDrugAndBatch(String drugName, String batchNumber)
    {
        return vetInventoryMapper.selectInventoryByDrugAndBatch(drugName, batchNumber);
    }
    
    /**
     * 根据药品名称查询最新的库存记录
     * 
     * @param drugName 药品名称
     * @return 最新库存信息
     */
    @Override
    public VetInventory selectLatestInventoryByDrug(String drugName)
    {
        return vetInventoryMapper.selectLatestInventoryByDrug(drugName);
    }

    /**
     * 更新库存数量
     * 
     * @param inventoryId 库存ID
     * @param quantity 数量变化
     * @return 结果
     */
    @Override
    public int updateInventoryQuantity(Long inventoryId, Integer quantity)
    {
        return vetInventoryMapper.updateInventoryQuantity(inventoryId, quantity);
    }
    
    /**
     * 根据关键词搜索库存商品
     * 
     * @param keyword 关键词
     * @return 库存列表
     */
    @Override
    public List<VetInventory> searchInventoryByKeyword(String keyword) {
        VetInventory vetInventory = new VetInventory();
        vetInventory.setDrugName(keyword);
        return vetInventoryMapper.selectVetInventoryList(vetInventory);
    }
}